/**
 * 
 */
function sendRadomNum() {
	$.post("sendRadomNum", "mobile=" + $("#desmobile").val(), function(a) {
		var b = JSON.parse(a);
		d = b.rsp_desc;
		layer.msg(d);
	})
}
function radomLogin() {
	password = $("#password").val();
	mobile = $("#desmobile").val();
	$.post("radomLogin", {
		'password': password,
		'mobile': mobile
	}, function(a) {
		if (mobile == "") {
			layer.msg("登陆失败")
		} else if (a.indexOf(mobile) > -1) {
			layer.msg("登陆成功");
			long();
		} else {
			layer.msg("登陆失败")
		}
	})
}

function readyList(){
	mobile = $("#desmobile").val();
	if(mobile==''){
		layer.msg('请输入手机号');
		return ;
	}
	console.log(window.location.search);
	var totalRowText='<font color="red">已获得的话费数据</font>';
	var totalRowDate='<font color="red">数据更新于'+getNowFormatDate()+'</font>';
	getData('readyList'+'?mobile='+mobile,totalRowText,totalRowDate);
}
function noReadyList(){
	mobile = $("#desmobile").val();
	if(mobile==''){
		layer.msg('请输入手机号');
		return ;
	}
	var totalRowText='<font color="red">在路上的话费数据</font>';
	var totalRowDate='<font color="red">数据更新于'+getNowFormatDate()+'</font>';
	getData('noReadyList'+'?mobile='+mobile,totalRowText,totalRowDate);
}
function loseList(){
	mobile = $("#desmobile").val();
	if(mobile==''){
		layer.msg('请输入手机号');
		return ;
	}
	var totalRowText='<font color="red">失效的话费数据</font>';
	var totalRowDate='<font color="red">数据更新于'+getNowFormatDate()+'</font>';
	getData('loseList'+'?mobile='+mobile,totalRowText,totalRowDate);
}
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    return currentdate;
}
function getData(url,totalRowText,totalRowDate){
	var encryptmobile=$("#encryptmobile").val();
	if(encryptmobile==""){
		layer.msg('请先完成登陆');
		return 
	}
		layui.use('table', function(){
			  var table = layui.table;
			  var laypage = layui.laypage;
			  table.render({
			    elem: '#demo'
			    ,url:url+"&encryptmobile="+encryptmobile
			    ,toolbar: true
			    ,totalRow: true
			    ,cellMinWidth: 80
			    ,cols: [[
			      {field:'id', title:'ID',fixed: 'left', unresize: true, sort: true, templet: '#indexTpl',totalRowText:totalRowText }
			      ,{field:'phonef', title:'大号',totalRowText:totalRowDate  }
			      ,{field:'phoneq', title:'小号'}
			      ,{field:'time', title:'时间', sort: true}
			      ,{field:'zhao', title:'余额', sort: true, totalRow: true}
			    ]]
		    ,even: true //隔行背景
			    ,response: {
			      statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
			    }
			    ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
			      return {
			    	 "code": '200',
			        "count": res.total/5, //解析数据长度
			        "data":res.listRelay
			      };
			    }
			  });
			});
}
function long(){
	$.ajax({
		url: "getLongInviCode",
		async: false,
		success: function(a) {
			if(a!="ck已失效，请重新登录"){
				$("#encryptmobile").val(a);
			}
		}
	})
}
function short(){
	var content;
	var encryptmobile=$("#encryptmobile").val();
	$.ajax({
		url: "getShortInviCode",
		data: {
			'encryptmobile': encryptmobile
		},
		async: false,
		success: function(a) {
			content=a;
		}
	})
	layer.open({
		  title: '短邀请码'
		  ,content: content
	});   
}
function twoFare(){
	$.ajax({
		url: "two",
		success: function(a) {
			if(a.indexOf("兑换成功")!=-1){
				layer.msg('兑换成功');
			}else if(a.indexOf("每月兑换话费值上限为30元")!=-1){
				layer.msg('当月兑换已经超过上限，下月再来吧');
			}else if(a.indexOf("登录失效,请重新登录")!=-1){
				layer.msg('登录失效,请重新登录');
			}else {
				layer.msg("兑换失败");
			}
			
		}
	})
}
function fiveFare(){
	$.ajax({
		url: "five",
		success: function(a) {
			if(a.indexOf("兑换成功")!=-1){
				layer.msg('兑换成功');
			}else if(a.indexOf("每月兑换话费值上限为30元")!=-1){
				layer.msg('当月兑换已经超过上限，下月再来吧');
			}else if(a.indexOf("登录失效,请重新登录")!=-1){
				layer.msg('登录失效,请重新登录');
			}else {
				layer.msg("兑换失败");
			}
			
		}
	})
}
function twentyFare(){
	$.ajax({
		url: "twenty",
		success: function(a) {
			if(a.indexOf("兑换成功")!=-1){
				layer.msg('兑换成功');
			}else if(a.indexOf("每月兑换话费值上限为30元")!=-1){
				layer.msg('当月兑换已经超过上限，下月再来吧');
			}else if(a.indexOf("登录失效,请重新登录")!=-1){
				layer.msg('登录失效,请重新登录');
			}else {
				layer.msg("兑换失败");
			}
			
		}
	})
}
